<template>
  <div>
    <!-- 搜索 -->
    <!-- 技术报告查询 - 维修工单选择 -->
    <TopFilter :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable height="auto" selectionType="single" ref="table" :columns="columns" :fetchapi="fetchapi" :params="fetchParams" :dataSource="dataList" :datakey="'rows'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange"> </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()" :disabled="disableds">添 加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
import { queryBalanceOrderForClaim }  from '@/api/dictionary/index';
import { getWxlxSelect } from '@/api/repair/repairReception/customer';
import { dictionary } from '@/utils/dictMixin';
export default {
   mixins: [dictionary],
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      disableds: true,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchapi:queryBalanceOrderForClaim,
      dateType: 'RO_CREATE_DATE',
      // fetchApi: getUser,
      fetchParams: {
        DATE_TYPE:'RO_CREATE_DATE'
      }, //ipa 接口
      selectedRows: [] //选中经销商
    };
  },
  created() {
       this.chuqi();
  },
  methods: {
    async chuqi(){
      const res = await getWxlxSelect();
      console.log(this.columns.find((x) => x.dataIndex === 'REPAIR_TYPE_CODE').dictItems);
      this.columns.find((x) => x.dataIndex === 'REPAIR_TYPE_CODE').dictItems = res.data.map((x) => ({
        value: x.REPAIR_TYPE_CODE + '',
        text: x.REPAIR_TYPE_NAME,
      }));
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '维修工单号', fieldName: 'RO_NO', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: 'VIN', fieldName: 'VIN', placeholder: '请输入', initialValue: '' },
        //{ type: 'SELECT', label: '工单开单时间', fieldName: 'VIN', placeholder: '请输入', initialValue: '' },
                //{ type: 'RANGE_DATE', label: '维修结算日期', fieldName: 'beginSettleAt|endSettleAt', placeholder: '请输入', initialValue: '' },

        { type: 'INPUT', label: '客户姓名', fieldName: 'OWNER_NAME', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '客户电话', fieldName: 'MOBILE', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '日期类型', fieldName: 'DATE_TYPE', placeholder: '请输入',initialValue: 'RO_CREATE_DATE',itemList: [{text: '工单开单时间', value: "RO_CREATE_DATE"}, {text: '维修结算时间', value: "BALANCE_TIME"}],
        rules: [{ required: true, message: '请选择日期类型', trigger: 'change' }],
        change: val => {
            if(val){
              let list = this.topFilterInit.find(x => x.fieldName === 'DATE_TYPE').itemList;
              const tmpValue = list.find(x => x.value === val).value;
              this.dateType = tmpValue;

            }
          }

        },
        { type: 'RANGE_DATE', label: '日期', fieldName: 'BEGIN_TIME|END_TIME', placeholder: '请输入', initialValue: '' },
        { type: 'SELECT', label: '索赔状态', fieldName: 'IS_PART_CLAIM', placeholder: '请输入', initialValue: '',itemList: this.createDictList('7532',[75321001]) },
      ];
    },
    //搜索获取数据
    changeHandle(val) {

      //let list = this.topFilterInit.find(x => x.fieldName === 'DATE_TYPE').itemList;
      //console.log(list,"list");
     //  console.log(list,"list");
      //this.dateType = list.find(x => x.value === val).value;

      this.fetchParams = Object.assign({}, this.fetchParams, val,{
        DATE_TYPE:this.dateType
      });
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '工单编号', dataIndex: 'RO_NO', sorter: true },
        { title: 'VIN', dataIndex: 'VIN', sorter: true },
        { title: '客户名称', dataIndex: 'OWNER_NAME', sorter: true },
        { title: '客户电话', dataIndex: 'MOBILE', sorter: true },
        { title: '车牌号', dataIndex: 'LICENSE', sorter: true },
        { title: '车型名称', dataIndex: 'MODEL_NAME', sorter: true },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          dictItems:[]
        },
        { title: '维修开始时间', dataIndex: 'RO_CREATE_DATE', sorter: true },
        { title: '维修结束时间', dataIndex: 'SQUARE_DATE', sorter: true },
        { title: '索赔状态', dataIndex: 'IS_PART_CLAIM', sorter: true , filterItems: this.createDictList(7532),
          dictItems: this.createDictList(7532)},
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      this.disableds = this.selectedRows.length <= 0;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      this.selectedRows.map(x => {
        x.roNo = x.RO_NO;
        x.vin = x.VIN;
        x.customerName = x.OWNER_NAME;
        x.customerPhone = x.MOBILE;
        x.licenseNo = x.LICENSE;
        x.modelName = x.MODEL_NAME;
        x.facName2 = x.REPAIR_TYPE_CODE;
        x.serviceBeginDate = x.RO_CREATE_DATE;
        x.serviceEndDate = x.SQUARE_DATE;
        x.serviceName = x.DELIVERER;
        x.servicePhone = x.DELIVERER_MOBILE;
        x.saleDate = x.SALES_DATE;
        x.prodDate = x.PRODUCT_DATE;
        x.repairBeginDate = x.WRT_BEGIN_DATE;
        x.useType = x.VEHICLE_PURPOSE;
        x.driveMile = x.IN_MILEAGE;
        x.applyName = x.CREATED_BY;
        x.modelId = x.MODEL;
        x.modelCode = x.MODEL_CODE;
      });
      this.$emit('save', this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    }
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
